Publishing a Chart

Learn how to publish a chart to a Helm repository.

Charts, like Kubernetes Dashboard or Postgres, require that we first add a Helm repository to our CLI and then do the installation. The goal of this lesson is to publish our Helm chart to a Helm repository without downloading any files first.

But what is a Helm repository? Basically it’s an HTTP server that provides an index.yaml file with some packaged charts. We’ve got tons of options from which we can choose one. A quite long—but not exhaustive—list with instructions can be found in the official documentation. However, we’ll use one of the most popular, GitHub’s free-to-use service, GitHub Pages.

Set up a GitHub page#

First, we need to have an account on GitHub (the register link is https://github.com/join). Once we have it follow the steps:

  1. Create: We create a new repository at https://github.com/new. We can name it whatever we want, e.g., helm-app.
  1. Add file: We should be redirected to a new repository page where we can add the first file to the repository, README.md. Next, we’ll be asked to fill it; but for now, we can keep it as the default, and then commit it.

  1. Select branch: We then click the “Settings” tab and go to “Pages” from where we can select a source branch. In our case, it will be the main branch. With this configuration we tell GitHub that it needs to treat this branch as the source of our resources.
Setting up a Git branch for a GitHub Page
Setting up a Git branch for a GitHub Page

  1. Save: After hitting the “Save” button we’ll finish the initial setup. The link to our GitHub page will be https://{yourusername}.github.io/helm-app/.

That’s it for setting up a GitHub repository to be used for publishing Helm charts.

In the next part of this lesson we’ll be committing and pushing code to GitHub. In order to do that we need to generate our personal access token. To do that, follow the instructions from the official website. Once we have it we’re good to go with publishing a Helm chart.

Package and publish Helm chart#

Next, we need to package our code into the .tgz archive file. It can be done with a simple command executed from a root folder of our repository:

Packaging a Helm chart

The output will be as follows:

Successfully packaged chart and saved it to: {YOUR_PATH}\helm-app\app-0.1.0.tgz

As a result, an app-0.1.0.tgz file has been created.

The last piece that needs to be added to a repository to make into a Helm repository is to add the index.yaml file. It holds metadata about the repository, including what Helm charts are available there (yes, we can store more than one chart in it). We could create it by hand, but luckily, there is a simple command for that (which should be executed in the root folder of a repository), as follows:

Generating the index.yaml file

This tool scans all the packages in the provided directory (in our case it’s the root, .) and generates a proper index.yaml file. We’ve also provided the --url flag to tell Helm what the address of our chart is. The URL is the same one that was displayed on the “Settings” page on GitHub. As a result, we should get a similar file, as follows:

apiVersionv1
entries:
  app:
  - apiVersionv2
    appVersion1.16.0
    created"2021-12-29T15:50:46.3146745+01:00"
    descriptionA Helm chart for Kubernetes
    digest7641cbb2a74ab85ad062a0ea0c1475d2faf219765583a401df0d825dab56a86a
    nameapp
    typeapplication
    urls:
    - https://{YOUR_GITHUB_USERNAME}.github.io/{YOUR_REPOSITORY_NAME}/app-0.1.0.tgz
    version0.1.0
generated"2021-12-29T15:50:46.3136758+01:00"

Everything is set up now so we can move forward with publishing it.

First, we need to initialize a Git repository in the root folder:

Initializing the Git repository

If we follow each step in a code playground, we might encounter a problem with identification while making a commit. In order to overcome it, we need to run the following two commands:

Setting a global username in Git
Setting a global email address in Git

Then the only thing to do is to commit all the changes, as follows:

Staging changes with Git
Committing changes to the Git repository

Once it’s committed we can add a link to the remote Github repository and push the changes there, as follows:

Adding a remote Git repository
Renaming the master branch to main
Publishing the changes to the Git repository

During the first commit, it is likely that we’ll be asked to provide a username and password. The first one is the GitHub account name and the latter is the personal access token that was mentioned previously.

Once it’s configured, we should be able to commit and publish changes to our GitHub repository.

Here is a code playground to test it:

/
app
README.md
The Helm chart to be published

We can go back now to GitHub and see that files have been uploaded there.

Using our public Helm chart#

Our Helm chart has been published, so it’s time to use it. The first thing to do is to add our Helm repository to a CLI, the way we did before installing the Kubernetes Dashboard and PostgreSQL:

Adding our Helm repository

The output:

"app-repo" has been added to your repositories

We can validate it with the following command:

Listing Helm repositories

The output will be as follows:

NAME                    URL
bitnami                 https://charts.bitnami.com/bitnami
app-repo                https://{YOUR_GITHUB_USERNAME}.github.io/{YOUR_REPOSITORY_NAME}

And finally, we can install a new application using it. Let’s reuse kanban-backend.yaml from a previous lesson and create the kanban-backend-2 release in a separate namespace, kanban-2, as follows.

Installing the second Kanban back-end service

This what the output will be:

Release "kanban-backend-2" does not exist. Installing it now.
NAME: kanban-backend-2
LAST DEPLOYED: Sun Aug  7 12:22:42 2022
NAMESPACE: kanban-2
STATUS: deployed
REVISION: 1
NOTES:
### 
######

kanban-backend-2, version: 1 has been installed, based on "app" Helm Chart!

Here is a short summary of installed application:

Docker base image: wkrzywiec/kanban-app:helm-course
Instances count: 1


######

Useful commands:

To list all Kubernetes resources created in this kanban-backend-2 Release:

    > kubectl get all --namespace kanban-2 -l app.kubernetes.io/version=kanban-backend-2-1

To establish connection with your app:

    > kubectl port-forward svc/kanban-backend 8080:8080 --namespace kanban-2 

After that it will be reachable at the address http://localhost:8080

######
###

Since we named our Helm repository app-repo and the name of the chart in it is app, the full name of the chart that we want to use would be app-repo/app.

/
postgres.yaml
kanban-backend.yaml
A Public chart sandbox

Run Tests for a Chart

Lint a Chart